//
//  ItemView.m
//  第六组电影项目
//
//  Created by 6-1 on 14-7-3.
//  Copyright (c) 2014年 www.skedu.com.cn北京尚德智远科技有限公司. All rights reserved.
//

#import "ItemView.h"

@implementation ItemView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self initSubView];
        [self addGesture];
    }
    return self;
}

-(void)initSubView
{
    _item=[[UIImageView alloc]initWithFrame:CGRectMake(self.width/2-11, 5, 22, 22)];
    _item.userInteractionEnabled=YES;
    _item.contentMode=UIViewContentModeScaleAspectFit;
    [self addSubview:_item];
    
    _title=[[UILabel alloc]initWithFrame:CGRectMake(0, _item.bottom+5, self.width, 10)];
    _title.textColor=[UIColor whiteColor];
    _title.backgroundColor=[UIColor clearColor];
    _title.textAlignment=NSTextAlignmentCenter;
    _title.font=[UIFont boldSystemFontOfSize:10];
    [self addSubview:_title];
}

-(void)addGesture
{
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didItemView:)];
    [self addGestureRecognizer:tap];
}

-(void)didItemView:(UITapGestureRecognizer *)tap{
    if ([self.delegate respondsToSelector:@selector(didItemView:atIndex:)]) {
        [self.delegate didItemView:self atIndex:self.tag];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
